<?php
/**
 * CFormButtonsPortlet class file.
 *
 * @author Lucas Vasconcelos <contato@lucasvasconcelos.com>
 * @copyright Copyright(c) 2010 Lucas Vasconcelos
 * @license BSD License http://www.lucasvasconcelos.com/yap/license
 * @link http://www.lucasvasconcelos.com/yap/
 * @version $Id: CFormButtonsPortlet.php 17 2010-02-04 20:20:10Z contato@lucasvasconcelos.com $
 * @package yap.web.portlets
 */

Prado::using('yap.web.portlets.CPortlet');

/**
 * CFormButtonsPortlet class.
 *
 * Botões 'Gravar' e 'Cancelar' para formulários.
 * Use em páginas derivadas de {@link CPageCrud}.
 *
 * @author Lucas Vasconcelos <contato@lucasvasconcelos.com>
 * @version 1.0 $Revision: 17 $
 * @package yap.web.portlets
 */
class CFormButtonsPortlet extends CPortlet
{
	public function getRequiredParent()
	{
		return 'IPageCrud';
	}
	
	public function save($sender,$param)
	{
		$this->getPage()->onSave(null);
	}
	
	public function cancel($sender,$param)
	{
		$this->getPage()->reload();
	}
	
	public function onLoad($param)
	{
		parent::onLoad($param);
		$this->configureLinks();
	}
	
	private function configureLinks()
	{
		if($this->NamingContainer instanceof CCrudPortlet)
		{
			$this->btn_save->ValidationGroup='vg_'.$this->NamingContainer->getAliasId();
			$this->btn_save->OnCommand=array($this->NamingContainer,'itemCommand');
			$this->btn_save->setCommandName(CActionType::Save);
			$this->btn_cancel->OnCommand=array($this->NamingContainer,'itemCommand');
		}
		else
		{
			$this->btn_save->OnClick=array($this,'save');
			$this->btn_cancel->OnClick=array($this,'cancel');
		}
	}
}